import { notification } from "antd";
import { useEffect } from "react";
import { Outlet, useLocation } from "react-router-dom";
import { isLogin } from "./utils/storage";

const NoNeedLoginPathList = ['/login']

const App: React.FC = () => {
	const theLocation = useLocation();

	const onPageChange = (pathname: string) => {
		if (
			!isLogin() &&
			NoNeedLoginPathList.indexOf(pathname) < 0 // 未登录且不在白名单页面之列，则前往登录
		) {
			notification.warning({
				message: '用户信息获取失败！',
				description: '未登录或登录失效，请重新登录',
				duration: 1.5,
				onClose() {
					window.location.replace("/login");
				}
			});
		}
	}

	useEffect(() => {
		// console.log("theLocation.pathname:", theLocation.pathname)
		onPageChange(theLocation.pathname);
	}, [theLocation.pathname])

	return <Outlet />
}

export default App;